﻿using System;
using System.Collections.Generic;
using System.Data;
using ReflectionStudio.Core.Events;
namespace WPFExcelReport
{

    public class WB08RData : BaseFunction
    {


        public WB08RData()
            : base()
        {

        }

        public WB08RData(Dictionary<string, object> DicGlobalPara)
            : base(DicGlobalPara)
        {
        }
        
        public DataSet BuildData(DataRow dwThis)
        {
            DataSet setReturn = new DataSet();
            DataSet dsResult = new DataSet();
            try
            { 
                orlReadCommand = OracleDB.CreateCommand();
                orlReadCommand.CommandText = "SELECT TRIM(WBBART)||'-'||TRIM(WBBFARBE)||'-'||WBBVAR AS ARTICLE, "
                    + " WBBDPART,BATCHQTY,BATCHMTR,"
                    + " UNCHECKEDQTY,UNCHECKEDMTR,CHECKEDQTY,CHECKEDMTR,DEFECTQTY,DEFECTMTR, "
                    + " (CASE WHEN BATCHQTY-NVL(UNCHECKEDQTY,0)-NVL(CHECKEDQTY,0)-NVL(DEFECTQTY,0)-NVL(REWORKQTY,0)-NVL(DELQTY,0)<0 "
                    + " THEN 0 ELSE BATCHQTY-NVL(UNCHECKEDQTY,0)-NVL(CHECKEDQTY,0)-NVL(DEFECTQTY,0)-NVL(REWORKQTY,0)-NVL(DELQTY,0) "
                    + " END ) AS FINISHQTY, "
                    + " (CASE WHEN (BATCHQTY-NVL(UNCHECKEDQTY,0)-NVL(CHECKEDQTY,0)-NVL(DEFECTQTY,0)-NVL(REWORKQTY,0)-NVL(DELQTY,0)>0) THEN  "
                    + " (BATCHMTR-NVL(UNCHECKEDMTR,0)-NVL(CHECKEDMTR,0)-NVL(DEFECTMTR,0)-NVL(REWORKMTR,0)-NVL(DELMTR,0)) ELSE 0 END ) AS FINISHMTR, "
                    + " REWORKQTY,REWORKMTR,DELQTY,DELMTR, "
                    + " NVL(UNCHECKEDQTY,0)+NVL(CHECKEDQTY,0)+NVL(DEFECTQTY,0) AS TOTQTY, "
                    + " NVL(UNCHECKEDMTR,0)+NVL(CHECKEDMTR,0)+NVL(DEFECTMTR,0) AS TOTMTR  "
                    + " FROM GREIGE_INVENTORY " ;
                dsResult = Connect2Proxy(orlReadCommand);
                if (dsResult.Tables.Count > 0)
                {
                    dsResult.Tables[0].TableName = "GREIGE_INVENTORY";
                    
                   /* byte[] b;
                    string value;
                    string ColumnName = "";
                    foreach (DataRow dwTemp in dsResult.Tables["GREIGE_INVENTORY"].Rows)
                    {
                        ColumnName = "WBBBESCHICH";
                        b = Encoding.GetEncoding("ISO-8859-1").GetBytes(dwTemp[ColumnName].ToString().Trim());
                        value = Encoding.GetEncoding("gb2312").GetString(b);
                        dwTemp[ColumnName] = value;
                    }*/
                }
                setReturn.Merge(dsResult);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return setReturn;
        }
    }
}